﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace SYH178DAL
{
    public class User_Info
    {
        #region 增

        #region 用户注册
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(SYH178Model.User_Info model)
        {
            SqlParameter[] param = {new SqlParameter("@LoginName",SqlDbType.VarChar,50),
                                 new SqlParameter("@Password",SqlDbType.VarChar,50),
                                 new SqlParameter("@Ip",SqlDbType.VarChar,50),
                                 new SqlParameter("@Type",SqlDbType.Int,4),
                                 new SqlParameter("@Mail",SqlDbType.VarChar,50)};
            param[0].Value = model.LoginName;
            param[1].Value = model.Password;
            param[2].Value = model.Ip;
            param[3].Value = model.Type;
            param[4].Value = model.Mail;

            int UserId = Common.SqlHelper.ExecuteNonQuery(SYH178Utils.Config.SYHConnStr, CommandType.StoredProcedure, "User_Info_Add", param);

            return UserId;
        }
        #endregion

        #endregion

        #region 查

        #region  验证登陆
        /// <summary>
        /// 验证登陆
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="passWord">登陆密码</param>
        /// <returns></returns>
        public int CheckLogin(string loginName, string passWord)
        {
            SqlParameter[] param = { new SqlParameter("@LoginName", SqlDbType.VarChar, 50),
                                   new SqlParameter("@Password",SqlDbType.VarChar,50)};
            param[0].Value = loginName;
            param[1].Value = passWord;

            int obj = Common.SqlHelper.ExecuteNonQuery(SYH178Utils.Config.SYHConnStr, CommandType.StoredProcedure, "User_Info_Check", param);

            return obj;
        }
        #endregion
        #endregion

        #region  改

        #region 修改密码
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="newPassWord">新密码</param>
        /// <returns></returns>
        public int UpdatePassWord(int userId, string newPassWord)
        {
            SqlParameter[] param = { new SqlParameter("@UserId",SqlDbType.Int, 4),
                                   new SqlParameter("@Password",SqlDbType.VarChar,50)};
            param[0].Value = userId;
            param[1].Value = newPassWord;

            int obj = Common.SqlHelper.ExecuteNonQuery(SYH178Utils.Config.SYHConnStr, CommandType.StoredProcedure, "User_Info_UpdatePassWord", param);

            return obj;
        }

        #endregion

        #region 修改邮箱
        /// <summary>
        /// 修改邮箱
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <param name="newMail">新密码</param>
        /// <returns></returns>
        public int UpdateMail(int userId, string newMail)
        {
            SqlParameter[] param = { new SqlParameter("@UserId",SqlDbType.Int, 4),
                                   new SqlParameter("@Mail",SqlDbType.VarChar,50)};
            param[0].Value = userId;
            param[1].Value = newMail;

            int obj = Common.SqlHelper.ExecuteNonQuery(SYH178Utils.Config.SYHConnStr, CommandType.StoredProcedure, "User_Info_UpdateMail", param);

            return obj;
        }
        #endregion
        #endregion
 
    }
}
